<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >  

    <ui:composition template="layout.xhtml">
        <ui:define name="corpo">
            <h:form id="buscar_form" acceptcharset="utf-8"> 
                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('config.xhtml')}" value="Configurações" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('indexAto.xhtml')}" value="Ato" update="@form" immediate="true"/> >
                    <p:commandLink  value="Cadastrar Ato" update="@form" immediate="true"/>
                </div>
                <p:panel header="Pesquisar Ato">
                    <p:messages showDetail="true"  id="msg" /> 

                    <h:panelGrid columns="2" id="panelGridEscolha" styleClass="textAlignRight"
                                 columnClasses="textAlignRight">
                        <h:outputLabel value="Código: " />
                        <p:inputText  value="#{managerConsultarAtoItem.atoItem.codigo}" size="20" />

                        <h:outputLabel  value="Descrição : " />
                        <p:inputText  value="#{managerConsultarAtoItem.atoItem.descricao}" size="50" />
                    </h:panelGrid>
                    <br/>
                    <div class="buttonAction">  
                        <p:commandButton value="Buscar"
                                         icon="ui-icon-search"
                                         actionListener="#{managerConsultarAtoItem.consultarAtoItem()}" 
                                         update="@form, atoTable, msg"/>
                        <p:commandButton icon="ui-icon-arrowreturnthick-1-w" 
                                         value="Cancelar" 
                                         actionListener="#{managerVisualizarAtoItem.redirect('indexAto.xhtml')}"
                                         immediate="true"/>
                    </div>
                    <br/>
                    <p:dataTable id="atoTable" var="ato" value="#{managerConsultarAtoItem.atoItens}" 
                                 paginator="true" rows="20"
                                 paginatorPosition="bottom"
                                 paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"  
                                 rowsPerPageTemplate="5,10,15">    

                        <f:facet name="header">  
                            Todos Atos Cadastrados 
                        </f:facet>
                        <p:column style="width:4%">  
                            <p:rowToggler />  
                        </p:column>  
                        <p:column  style="width:40px;">  
                            <f:facet name="header" >   
                                Codigo
                            </f:facet>  
                            <h:outputText value="#{ato.codigo}" style="font-weight: bold; float:right;"  />  
                        </p:column>

                        <p:column headerText="Descrição"> 
                            <h:outputText value="#{ato.descricao}"    />  
                        </p:column>
                        <p:column headerText="Selo" style="width:175px;">  
                            <h:outputText value="#{ato.tipoSelo.nome}"   />  
                        </p:column>
                        <p:column  headerText="Cor" style="width:40px;">  
                            <table>
                                <tr>
                                    <td class="borderZero" 
                                        style="height:25px; width: 10px; background-color: \##{ato.tipoSelo.corSelo.cor};"></td>
                                </tr>
                            </table>
                        </p:column>
                        <p:column headerText="Opções" style="width:55px;">  
                            <p:commandButton  icon="editar" style="width:25px; height:25px;" 
                                              actionListener="#{managerEditarAtoItem.redirect('editarAto.xhtml', ato)}" update="@form"/> 
                            <p:commandButton  icon="view" style="width:25px; height:25px;" 
                                              actionListener="#{managerVisualizarAtoItem.redirect('visualizarAto.xhtml', ato)}" 
                                              update="@form"/>  
                        </p:column>
                        <p:rowExpansion>  
                            <table style="width:100%">
                                <tbody style="background-color: #5277A9; color: #ffffff; ">
                                    <td style="font-weight: bold;">
                                        De
                                    </td>
                                    <td style="font-weight: bold;">
                                        Até
                                    </td>
                                    <td style="font-weight: bold; text-align: center;">
                                        Cartório
                                    </td>
                                    <td style="font-weight: bold; text-align: center;">
                                        Fermojupi
                                    </td>
                                    <td style="font-weight: bold; text-align: center;" >
                                        Valor
                                    </td>
                                    <td style="font-weight: bold; text-align: center;">
                                        OAB
                                    </td>
                                </tbody>
                                <ui:repeat value="#{managerEmolumento.findCodAto(ato.codigo)}" var="emol">
                                    <tr>
                                        <td >
                                            <h:outputText value="#{emol.valInicial eq null ? '-': emol.valInicial}" style="float:right;"/>  
                                        </td>
                                        <td >
                                            <h:outputText value="#{emol.valFinal eq null ? '-': emol.valFinal}" style="float:right;"/>  
                                        </td>
                                        <td >
                                            <h:outputText value="R$ #{emol.cartorio eq null ? '-': emol.cartorio}" style="float:right;"/>  
                                        </td>
                                        <td>
                                            <h:outputText value="R$ #{emol.fermojupi eq null ? '-': emol.fermojupi}" style="float:right;"/>  
                                        </td>
                                        <td>
                                            <h:outputText value="R$ #{emol.valor eq null ? '-': emol.valor}" style="float:right;"/>  
                                        </td>
                                        <td>
                                            <h:outputText value="#{emol.oab ? 'SIM' : 'NÃO'}" style="color: #{emol.oab ? 'green':'red'}; font-weight:bold;"/>  
                                        </td>
                                    </tr>
                                </ui:repeat>
                            </table>
                        </p:rowExpansion>
                    </p:dataTable> 

                    <br/>
                    
                </p:panel>

            </h:form>
        </ui:define>
    </ui:composition>
</html>
